const app = getApp()
const state = [
  {
    name: "就医档案",
    id: 1,
    arr: [
      {name:"我的订单",img: "/assets/image/user1.png",type: 1},
      {name:"门诊清单",img: "/assets/image/user2.png",type: 2},
      {name:"住院清单",img: "/assets/image/user3.png",type: 3},
    ]
  },
  {
    name: "医疗服务",
    id: 2,
    arr: [
      {name:"物价查询",img: "/assets/image/user4.png",type: 20},
      {name:"报告查询",img: "/assets/image/user5.png",type: 21},
    ]
  }
]
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    state,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    app.ws.setBadge()
    this.getUserInfo()
  },

  async getUserInfo() {
    this.setData({
      userInfo: await app.getUserInfo()
    },() => {
      
    })
  },

  onClickLeft() {
    wx.navigateTo({
      url: '/pages/user/visitorList/index',
    })
  },

  onClickRight() {
    wx.navigateTo({
      url: '/pages/user/satisfaction/list/index',
    })
  },

  onClickBottom(e) {
    const type = e.currentTarget.dataset.type
    switch (type) {
      case 1:
        
        break;
      case 2:
        wx.navigateTo({
          url: '/pages/user/inventory/index?activeTab=a',
        })    
        break;
      case 3:
        wx.navigateTo({
          url: '/pages/user/inventory/index?activeTab=b',
        })    
        break;
      case 20:
        wx.navigateTo({
          url: '/pages/user/priceInquiry/index',
        })
        break;
      case 21:
        wx.navigateTo({
          url: '/pages/user/report/index',
        })
        break;
      default:
        break;
    }
  },
  
  onEdit(){
    const item = this.data.userInfo
    const ops = {
      id: item.id,
      name: item.name,
      gender: item.gender,
      birth: item.birth,
      id_number: item.id_number,
      nation: item.nation,
      area: item.area || [],
      area_detail: item.area_detail,
      phone: item.phone,
    }
    wx.navigateTo({
      url: '/pages/user/visitorEdit/index?item=' + JSON.stringify(ops),
    })
  },


  onClickExit() {
    app.ws.close()
    wx.clearStorage()
    wx.reLaunch({
      url: '/pages/login/index',
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})